import {AbstractControl, FormGroup} from '@angular/forms';
import * as CryptoJS from 'crypto-js';

export const passwordWeak = '1234567891234567890a123456789qq123456abc123456123456789aWOAINI131412345678111111111231231238888888811111111114725836998765432111111111111qaz2wsx78945' +
  '6123iloveyouqwertyuiopasdfghjkl1q2w3e4r123456abcqazwsxedcabcd1234123654789aa1234561233211231234qwer123456aa123456123999999999741852963963852741qwer1234qweasdzxcasd123456123456qq' +
  '3.1415926asdf1234111222333147852369123698745woaiwojia123456987zxcvbnm12358452013141q2w3e4r5tbuzhidaoxiaoxiaoqwe1234561357924680yangyang135792468AS123456147896325aaaaaaaa11223344' +
  'password876543211234432131415926asdasdasd1212121212341234a12345678asdfasdfqwertyui520520520q1w2e3r41234abcd1qazxsw21123581321123456asdwoaini123woshishui1230123012345543211236987' +
  '425257758369258147zhang123woainimawoaini520584521131412345678910jingjingtiantian5841314215841314520yuanyuanwoailaopo5841314200000000066666666qqqqqqqq0000000000000000000012345678' +
  '911011011022222222a123456711112222521521521123qweasd112358135201314520100200300qazwsx123wocaonimaq1234567899876543210qaz123456123456QWE20082008qq123123WOJIUSHIWOsunshinewodemimaa' +
  '5201314zhangwei110120119123456789qwoaini521dongdong131413142008080814789632aini1314zhangleiworinimaqq5201314zhangjiewangyanglove13145842013149999999912345612345655555555asdfghjk' +
  '12345678A321321321123456001234566543210987654321z12345678912345679123456aaa1233211234567321654987zxc123456computersupermangoodlucka123456a12qwaszx12345qwertaptx48697758521074108' +
  '5207894561230abcd123456mingmingshanghaiwangjianwww1234567758521521qq12345678925251325wangjing1101191201314520520nicholas5201314awobuzhidaoxiaoqiang16897168longlongxiaolongshansh' +
  'an1101201305841314521zhangjianww111111hao123456woaiwozijizhendeainijiushiainims0083jxj33333333qweqweqweffffffff1234567aaaa123456qwerasdf299792458123456789.8888888888520131452013' +
  '14888888888abc12345a123123123123456..12312312a1b2c3d4abc1234567891a2b3c4d123456abli123456qq000000qw123456w1234567891234512345456456456ab123456Q1W2E3R4T519491001zz123456123qwe123' +
  '775852177585211234567890123123456aschenchenq1234567123456qazqwert12345520131403141592653qweasd12352013141314wang123456asdf1234561234567981234567899liu123456123456789abc123456qw1' +
  '23456abcd74107410ddzj39cb3zx12345620092009nihao123lxqqqqqqwoainiwoaini19861212liangliang12345678912313145201314520eladnbin110419861015123456zxcqwe123qwe5201314123zhangyan123456.' +
  '..476730751mm123456wangyut21.23457E+11aa5201314caonima1231346798521.23456E+11ww1234561.23457E+12qwert1230.123456abc12345671111111111111111tingtingdearbookcode8925zzzzzzzz7777777' +
  '7xiazhili88771024wwwwwwww1010101012345678A@44444444112233445512345612P@ssw0rdcsdncsdn05962514787sssssssslilylilyddddddddzxczxczxc369369369aaaaaaaaaabcdefgh1237894561983020916816' +
  '8168helloworldaaaaaaaaaa112233445566zaq12wsxxxxxxxxxds760206123321123321789789789qq11111113145200a1111111google250123321aa00700700766668888csdn.netaaaa1111maidoumaidouz325550001' +
  '234567212121210000111112345687123487650102030423232323qkvmlia569passw0rd7758521101010101a11111111aa123123mmmmmmmmqazqazqaz200919abqazxswedc1984101020102010666666666111111aa19841' +
  '020198109141234560001020304012312312312312345abcde13801001020meiyoumima5185185185200251314hahahaha13131313fa1681688llllllll19851010asasasas01234567877889900newhappy234567891236' +
  '54781111qqqqwangpengz1234567w1234567dgdg7234322qqqq11111234asdf1234567b951ljb75345612300justdoitq111111111111111aqqqqqqqqq198410289119119111111000019841021microsoft2582582581234' +
  '54321987456321qwqwqwqw19841018159159159123123aajjjjjjjjhhhhhhhhppppppppq1234567819841012456789123administratora0000000admin123loveloveinterneta0000000019841023120120120asd123123' +
  'kkkkkkkk12131415admin36984131421ybnkoia569testtest19851120420111781qaz2wsx3edc12332100787878786677889919871024456123789z12345678123123456123456zxmac1234568888999911111111111147' +
  '14714755667788miaomiaoqwe123123123321121qaz1qazccccccccqkvpoia569youaifa569oooooooo123123001111111aimissyou33333333319841011zhimakaimenxingxing135724681984102419850603asdasd12' +
  '3asd12345qwe12345qwerty123555555555512233344441982101019871025314159265410293847561984100119861020369852147handsome1230000012345678Q1689916899998888a1s2d3f4qqq1111119851023198' +
  '5102519851212112112112songguangaaa123123aaaa000019871212zxcv12349876543298989898789654123yyyyyyyy111111qq963852741986101219861013gggggggg6666666666198510131985101919841026198' +
  '41022198512181986112219841015windowsxpQQQQQqqqqq1234561112345645615975312311221122hello123198611111q1q1q1qqazhuang123abc12345678woshitiancai119119119198711251986102819851125198' +
  '510201982101619861016198611201984101719881010wangwang123123qq1987101219841027111222tianya393041123dedewang634142554googletester811224baiaz1234563353212limajiajunEtnXtxSa65story' +
  'ofall650829yjm774517397sgdHhfC4x2wsky0o0o0o9YUE27RI19960309NBvBB32fa920062006kb9zc8uxtx2199127551463395727ApjSqpM844fashion@000s1t2o3n4ye123456uifKjhF522ndaCebx2wxJxsGx2Yd87ji' +
  'anfei000sxUaIehAtp858877108aop2m66xF2AJTwanshuai198202789654321vjfLkiG522z1122334455benq*edifer19891229qfcFgdA3zxd54q7xjmhx6Cxd2X986xPCwAC33gb919871015b33m6yghefxm55xExBZSmcaB' +
  'daw2vxd54p7xjkhaCrkUrrP9543uc9xN53xH4wdaxQ642Fi97wb6sxq719991226theIigD4x2953684521774605224081986syq20071003linjiangfuanyue47yx12345678operation1.11111E+17asd45679xiaofengnis' +
  'hiwoer86944950woshishen19880405huizhangszc0313719840504200523241.23457E+17woshishei316032611zhanghang1063524602woshizhuwokaonima3939889034416912zhanghaoNISHIZHUjianjian81151007' +
  'lee01301228shangxinwoshiniba19871206fengfengdd123456wangchaoa453896121986101819861225zzb19860526love1314agoyj20101172897881310613106xaoyin78admin1234123456hrrg13916055158da2khd' +
  'ahda19810625qiye123456ok100404x50862356itbbs20101208PCloveyou1314@sohu.com132456128844.8844ex5086721288448844seoer2010liudu88888jkhldfkf12djlm292979123456rtsidake2bnliuping200' +
  'kissbaby78157878woyaolp512123456okyixin2011abc123dddadf46sdfsf5201314qyy55yy88xkhl656266runsystemhjl80033913bqueensss85665684a123456b86815945a88778877aa112288xkl656266787878ka' +
  'ityc99tycaayj123456zhong133bqueenssssliuping1920831101qslasdqwe22789457dweweeliuli123poow29q6666lingnan123a123b456nurk20212188888888zzklaozi124leon123456123sv67e91148878306414' +
  '512@QQ.comhld_1209along0321feadsf3dW@*$#*#$#,3edc4rfv519851030123456Bc123678dd123654yyykuai+321=Wen_1235580817aaano1444888tongji5613aw123123zxcvbnm111LGL6641341198511180215894' +
  '998@qq.com62379372agiene8547admdfdsfsddmashuguangdmba88981234567890000dg123456fcqq12346yinchuanqilove8023hyp815822jo@qq.ccchenqingeohank19806184685521aa998877123456acokok58858' +
  '8nihao789199707010198612501237708801314520123456789001234567891123456789qq14725836901234567891234567qwertyuiop123aa12345678972152177589919638527410wo123456zhang123456asdfghjk' +
  'l123woaini5201314ABCD123456789qwertyuio123456789aawoaini1314520asd123456789woaini12345612345678998765437758521131413579246810zxcvbnm,./5205201314123456789z13800138000123456789' +
  'w123456789+abcdefg123a1314520www1234567890000000000000000qwe123456789123456789asd12345678912qqq123456123456789*01472583695211314521laopowoainiyang123456qq1314520qaz123456789ai' +
  'niyiwanniana147258369l123456789aaa123456789woainilaopoabcd1234552013140012131415167418529630nuttertools1314520123123456789aaaas123456789123456789QWEzxcvbnm123456123456789..qwe' +
  'r123456wo123456789123456789abcd77585211231234567890.123456789lab1234567891111122222chen123456a987654321qw123456789zxc123456789li123456789775825852077582581314258iloveyou1314qa' +
  'zwsxedcrfv987654321a1314woaini123698741huang123qwertyuiop1234561314521521200820082008qq1234567123456776543210.123456789poiuytrewqwoxiangni123456789m741741747474152013147891234' +
  '56789zxc123456789qaz123456789520ai12345652013143344abcde12345Love5201314775852100yongyuanaini131452000147258369awoxihuanni123456tt134679258zxcvbnm1234567891234565207758258123q' +
  'azwsx123456abcdefg123456123abc456woaini1314.wang123456789s1234567891357913579abc5201314zhangjing12345678025825877581234567890a13145201314520131488a775852174108520963.Y12345678' +
  '90102030405065201314.q5201314789632145huang123456LAOpo520xiao123456LAOPO521woaiwolaopozxcv123456m1234567897410852963yu123456123456789ab5201314qqx123456789123456788a1234567890BE' +
  'IJING2008wu123456123456qqq110112119246813579aidejiushiniw5201314h123456789qq147258369yy123456102030405060123012301230zhangqiangasdfghjkl;zhao123456caonimabiwoaini3344987654321' +
  '00123woainiWOSHINIDIE12345678999123456789aswoaini110123456789p77582581314wei123456womendeai00123456789mengmengduibuqiwoainiiloveyou520zhangyang@163.comAdgjmptw7.7088E+12woaini' +
  '1311.23321E+12@126.comwoaini525.20131E+13147258367.21522E+12';

export function passwordGroupValidator(group: AbstractControl): any {
  const p1 = group.get('password').value;
  const p2 = group.get('passwordCheck').value;
  if (p1 !== null && p2 !== null) {
    if (p1.length < 8 || p1.length > 16) {
      return '密码位数不正确';
    }
    if (passwordWeak.indexOf(p1) >= 0) {
      return '密码为弱类型';
    }
  }
  return p1 !== p2 ? '密码不匹配' : null;
}

export class User {
  alias: string;
  username: string;
  password: string;
  cellphone_number: string;
  email: string;
  permission_group: number;

  constructor() {
  }

  public fromForm(form: FormGroup): User {
    this.alias = form.get('alias').value;
    this.username = form.get('username').value;
    this.password = form.get('passwordGroup.password').value;
    this.cellphone_number = form.get('cellphone_number').value;
    this.email = form.get('email').value;
    this.permission_group = form.get('permission_group').value;
    return this;
  }

  public md5(): User {
    this.password = CryptoJS.MD5(this.password).toString();
    return this;
  }

}


